<template>
  <div>

    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body class="abow_dialog"
               :close-on-click-modal="false" v-dialogDrag>
      <!-- 添加或修改sysArea对话框 -->
      <el-form ref="form" :model="form" size="mini" :rules="rules" label-width="120px" style="height: 100%;">
        <el-tabs v-model="activeName" class="detail-tab" type="card">
          <el-tab-pane label="基本信息" name="first">
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="父部门id" prop="parentId">
                  <el-input v-model="form.parentId" placeholder="请输入父部门id"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="部门名称" prop="deptName">
                  <el-input v-model="form.deptName" placeholder="请输入部门名称"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="显示顺序" prop="orderNum">
                  <el-input v-model="form.orderNum" placeholder="请输入显示顺序"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="负责人" prop="leader">
                  <el-input v-model="form.leader" placeholder="请输入负责人"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="联系电话" prop="phone">
                  <el-input v-model="form.phone" placeholder="请输入联系电话"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="邮箱" prop="email">
                  <el-input v-model="form.email" placeholder="请输入邮箱"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="部门状态">
                  <el-radio-group v-model="form.status">
                    <el-radio label="1">请选择字典生成</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="删除标志" prop="delFlag">
                  <el-input v-model="form.delFlag" placeholder="请输入删除标志"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="机构类型" prop="type">
                  <el-select v-model="form.type" placeholder="请选择机构类型">
                    <el-option label="请选择字典生成" value=""/>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="机构等级" prop="grade">
                  <el-input v-model="form.grade" placeholder="请输入机构等级"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="备注信息" prop="remarks">
                  <el-input v-model="form.remarks" placeholder="请输入备注信息"/>
                </el-form-item>
              </el-col>
            </el-row>
          </el-tab-pane>
        </el-tabs>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>

    </el-dialog>

  </div>
</template>

<script>
    import {listArea, getArea, delArea, addArea, updateArea, exportArea} from "@/api/sysArea/area";

    export default {
        name: "Area",
        components: {},
        data() {
            return {
                // 遮罩层
                loading: true,
                activeName: "first",
                title: "",
                open: false,
                // 表单参数
                form: {},
                // 表单校验
                rules: {}
            };
        },
        created() {
        },
        methods: {
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            handleAdd() {
                this.open = true;
                this.title = "添加sysArea";
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
                    deptId: null,
                    parentId: null,
                    ancestors: null,
                    deptName: null,
                    orderNum: null,
                    leader: null,
                    phone: null,
                    email: null,
                    status: "0",
                    delFlag: null,
                    createBy: null,
                    createTime: null,
                    updateBy: null,
                    updateTime: null,
                    type: null,
                    grade: null,
                    remarks: null
                };
                this.resetForm("form");
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.deptId != null) {
                            updateArea(this.form).then(response => {
                                this.msgSuccess("修改成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        } else {
                            addArea(this.form).then(response => {
                                this.msgSuccess("新增成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        }
                    }
                });
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.reset();
                const deptId = row.deptId || this.ids
                getArea(deptId).then(response => {
                    this.form = response.data;
                    this.open = true;
                    this.title = "修改sysArea";
                });
            }

        }
    };
</script>
